package com.cuz.hot100;


import com.cuz.hot100.datastruck.ListNode;

public class Q82deleteDuplicates {
    public static void main(String[] args) {
        ListNode listNode = ListNode.creatBy(1, 1);
        deleteDuplicates1(listNode).print();
    }

    public static ListNode deleteDuplicates1(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode preHead = new ListNode();
        preHead.next = head;
        ListNode cur = preHead;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int duplicateValue = cur.next.val;
                while (cur.next != null && cur.next.val == duplicateValue) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }
        return preHead.next;
    }
}
